import { GSprite } from "../../../../com/mui/controls/GSprite";
import { ItemData } from "../../resource/info/ItemData";
import { PlayerEquipItem } from "../common/PlayerEquipItem";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { EffectManager } from "../../manager/EffectManager";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EDressPos } from "../../../../Message/Public/EDressPos";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { EPlayerItemPosType } from "../../../../Message/Public/EPlayerItemPosType";
import { ToolTipInfo } from "../../model/ToolTipInfo";
import { EquipmentToolTipData } from "../../resource/info/EquipmentToolTipData";
import { Tooltip } from "../common/tooltip/Tooltip";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { BaseItem } from "../common/BaseItem";
import { DataEvent } from "../../events/DataEvent";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { IDragDrop } from "../../../../com/mui/manager/IDragDrop";
import { _EDressSpiritPosChaosHead } from "../../../../EDressPos/_EDressSpiritPosChaosHead";
import { _EDressSpiritPosChaosNeck } from "../../../../EDressPos/_EDressSpiritPosChaosNeck";
import { _EDressSpiritPosChaosBody } from "../../../../EDressPos/_EDressSpiritPosChaosBody";
import { _EDressSpiritPosChaosTail } from "../../../../EDressPos/_EDressSpiritPosChaosTail";
import { _EDressSpiritPosChaosLeftPaw } from "../../../../EDressPos/_EDressSpiritPosChaosLeftPaw";
import { _EDressSpiritPosChaosRightPaw } from "../../../../EDressPos/_EDressSpiritPosChaosRightPaw";
import { _EDressSpiritPosChaosLeftLeg } from "../../../../EDressPos/_EDressSpiritPosChaosLeftLeg";
import { _EDressSpiritPosChaosRightLeg } from "../../../../EDressPos/_EDressSpiritPosChaosRightLeg";
type int = number;
//class SpiritEquipPanel
    
    export  class SpiritEquipPanel extends GSprite
    {
        constructor()
        {
            super();
            this._equipItemArr = [];
            this._allEquipmentsOnPlayer = [];
            this.init();
            return;
        }

        public selectByItemData(arg1: ItemData): void
        {
            var loc1=null;
            var loc2=false;
            var loc3=0;
            while (loc3 < this._equipItemArr.length) 
            {
                loc1 = this._equipItemArr[loc3] as PlayerEquipItem;
                loc2 = ItemsUtil.isSpiritEquipHDEnable(loc1.itemData);
                if (arg1) 
                {
                    if (loc1 && loc1.itemData && loc1.itemData.type == arg1.type) 
                    {
                        EffectManager.glowFilterReg(loc1);
                        if (loc2) 
                        {
                            EffectManager.glowFilterReg(loc1);
                        }
                        else 
                        {
                            loc1.filters = [FilterConst.colorFilter];
                        }
                    }
                    else 
                    {
                        EffectManager.glowFilterUnReg(loc1);
                        if (loc2) 
                        {
                            loc1.filters = null;
                        }
                        else 
                        {
                            loc1.filters = [FilterConst.colorFilter];
                        }
                    }
                }
                else 
                {
                    EffectManager.glowFilterUnReg(loc1);
                    if (loc2) 
                    {
                        loc1.filters = null;
                    }
                    else 
                    {
                        loc1.filters = [FilterConst.colorFilter];
                    }
                }
                ++loc3;
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc4=null;
            var loc7=0;
            if (this._equipTypeArr == null) 
            {
                loc7 = ECategory._ECategorySpiritEquip;
                this._equipTypeArr = [{"cate": loc7, "type": _EDressSpiritPosChaosHead}, {"cate": loc7, "type": _EDressSpiritPosChaosNeck}, {"cate": loc7, "type": _EDressSpiritPosChaosBody}, {"cate": loc7, "type": _EDressSpiritPosChaosTail}, {"cate": loc7, "type": _EDressSpiritPosChaosLeftPaw}, {"cate": loc7, "type": _EDressSpiritPosChaosRightPaw}, {"cate": loc7, "type": _EDressSpiritPosChaosLeftLeg}, {"cate": loc7, "type": _EDressSpiritPosChaosRightLeg}];
            }
            var loc1=25;
            var loc2=30;
            var loc3=this._equipTypeArr.length;
            var loc5=Object;
            this._equipItemArr.splice(0);
            var loc6=0;
            while (loc6 < this._equipTypeArr.length) 
            {
                loc5 = this._equipTypeArr[loc6];
                (loc4 = ObjectPool.getObject(PlayerEquipItem)).setOverPosition(-2, -2);
                loc4.setSize(33, 33);
                loc4.dropChecktFunction = this.canDrop;
                loc4.isDragAble = false;
                loc4.isThrowAble = false;
                loc4.doubleClickEnabled = false;
                loc4.toolTipDataFunction = this.getToolTipData;
                loc4.posType = EPlayerItemPosType._EPlayerItemPosTypeRole;
                loc4.posIndex = loc5.type;
                loc4.x = loc1;
                loc4.y = loc2;
                loc4.setNormalEquipBg(loc5.cate, loc5.type);
                loc2 = loc2 + 45;
                if (loc6 == 3) 
                {
                    loc1 = 345;
                    loc2 = 30;
                }
                addChild(loc4);
                this._equipItemArr.push(loc4);
                ++loc6;
            }
            return;
        }

        /* internal  */getToolTipData(arg1: PlayerEquipItem): ToolTipInfo
        {
            var loc1=null;
            if (arg1.itemData) 
            {
                loc1 = new EquipmentToolTipData(arg1.itemData, this._allEquipmentsOnPlayer);
                return new ToolTipInfo(Tooltip.ToolTipRenderType_Equipment, loc1);
            }
            return null;
        }

        public updatePosIndex(arg1: int): void
        {
            return;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            this.updateEquipItemOpt();
            return;
        }

        /* internal  */updateEquipItemOpt(): void
        {
            var loc2=null;
            var loc3=0;
            var loc1=this._equipItemArr.length;
            loc3 = 0;
            while (loc3 < loc1) 
            {
                loc2 = this._equipItemArr[loc3] as PlayerEquipItem;
                if (loc2) 
                {
                    if (this._mode != GModuleEvent.Mode_Self) 
                    {
                        loc2.isDragAble = false;
                    }
                    else 
                    {
                        loc2.isDragAble = true;
                        loc2.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onItemDoubleClick);
                        loc2.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onItemDown);
                    }
                }
                ++loc3;
            }
            return;
        }

        /* internal  */onItemDoubleClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as BaseItem;
            if (loc1 && loc1.itemData) 
            {
                this.dispatchEvent(new DataEvent(GModuleEvent.Event_unDress, {"uid": loc1.itemData.uid, "index": loc1.posIndex}, false, true));
            }
            return;
        }

        /* internal  */onItemDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            if (arg1.ctrlKey) 
            {
                loc1 = arg1.target as BaseItem;
                if (loc1 && loc1.itemData) 
                {
                    loc2 = Cache.instance.pack.rolePackCache.getItemDataByUid(loc1.itemData.uid);
                    if (loc2) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ChatShowItem, loc2));
                    }
                }
            }
            return;
        }

        public canDrop(arg1: IDragDrop, arg2: IDragDrop): Boolean
        {
            var loc1=arg1 as BaseItem;
            if (loc1.posType == EPlayerItemPosType._EPlayerItemPosTypeRole) 
            {
                return false;
            }
            if (loc1) 
            {
                if (loc1.itemData.itemInfo.item.category == ECategory._ECategorySpiritEquip) 
                {
                    return true;
                }
                return false;
            }
            return false;
        }

        public updateSpiritEquip(arg1: Array<any>): void
        {
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            this._allEquipmentsOnPlayer = arg1;
            var loc1=arg1.length;
            var loc2=this._equipItemArr.length;
            loc5 = 0;
            while (loc5 < loc2) 
            {
                if (loc4 = this._equipItemArr[loc5] as PlayerEquipItem) 
                {
                    loc4.itemData = null;
                }
                ++loc5;
            }
            loc5 = 0;
            while (loc5 < loc1) 
            {
                loc3 = arg1[loc5];
                loc6 = 0;
                while (loc6 < loc2) 
                {
                    loc4 = this._equipItemArr[loc6] as PlayerEquipItem;
                    if (loc3 && loc4 && loc3.category == loc4.category && loc3.effectEx == loc4.posIndex) 
                    {
                        loc4.itemData = loc3;
                        if (ItemsUtil.isSpiritEquipHDEnable(loc3)) 
                        {
                            loc4.filters = null;
                        }
                        else 
                        {
                            loc4.filters = [FilterConst.colorFilter];
                        }
                    }
                    ++loc6;
                }
                ++loc5;
            }
            return;
        }

        /* internal */ /* var */_equipItemArr: Array<any>;

        /* internal */ /* var */_equipTypeArr: Array<any>;

        /* internal */ /* var */_mode: string="自己";

        /* internal */ /* var */_allEquipmentsOnPlayer: Array<any>;
    }
